<template>
  <h3>04-为 computed() 标注类型</h3>
</template>

<script setup lang="ts">
import { ref, computed } from "vue";

const count = ref(0);

// 推导得到的类型：ComputedRef<number>
const double = computed<number | string>(() => {
  return count.value > 2 ? "100" : count.value * 2;
});

// => TS Error: Property 'split' does not exist on type 'number'
if (typeof double.value === "string") {
  const result = double.value.split("");
} else {
  const result = double.value.toFixed(2);
}
</script>
